<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>   
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<sql:setDataSource driver="com.mysql.jdbc.Driver"
	user="Caizi"
	password="tang"
	url="jdbc:mysql://localhost/book"
	var="ds"
	scope="page"
/>
<sql:query var="rs" dataSource="${ds }" scope="page">
	select * from books
</sql:query>
<table>
<c:forEach var="row" items="${rs.rows }">	<!-- 循环数据的每一行 -->
<tr>
	<td>${row.id }</td>
	<td>${row.name }</td>
	<td>${row.author }</td>
	<td>${row.price }</td>
	<td>${row.publisher }</td>
</tr>
</c:forEach>
</table>

<table>
<c:forEach var="row" items="${rs.rows }">
<tr>												<!-- 在不知道数据名的情况下 -->
	<c:forEach var="col" items="${rs.columnNames }">	<!-- 得到每一行的名字 -->	
		<td>${row[col] }</td>
	</c:forEach>
</tr>
</c:forEach>

</table>
</body>
</html>